﻿using PiCompressor.Console.Properties;
using System.Numerics;

namespace PiCompressor.Console
{
    public sealed class RealPi : IPiCalculator<string>
    {
        public ValueTask<string> CalculatePiAsync(BigInteger length)
        {
            if (length < 0 || length > int.MaxValue)
            {
                // string 也就只能支持到 int.MaxValue 了。
                throw new ArgumentOutOfRangeException(nameof(length));
            }
            var result = Resources.Pi[0..(int)length];
            return ValueTask.FromResult(result);
        }

        public async ValueTask<BigInteger?> MeasureLengthAsync(string pi)
        {
            return
                await CalculatePiAsync(pi.Length) == pi ?
                pi.Length : null;
        }
    }
}
